package com.dby.controller;

import com.dby.entry.BlogUser;
import com.dby.mapper.BlogUserMapper;
import com.dby.service.BlogUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @RequestMapping("/admin/login")
    public String login() {
        return "/admin/userlogin";
    }

    @RequestMapping("/admin/home")
    public String home() {
        return "/admin/index";
    }
    @Autowired
    BlogUserService blogUserService;
    @Autowired
    HttpSession httpSession;
    @RequestMapping("/loginAction")
    public String loginAction(String username,String password) {
        System.out.println(username);
        System.out.println(password);
        BlogUser blogUser = blogUserService.getBlogUserByUserCode(username);
        if(blogUser!=null){
            if(password.equals(blogUser.getUserPwd())){
                httpSession.setAttribute("blogUser",blogUser);
                return "/admin/home";
            }
        }
        return "/admin/login";
    }
}